<?php
/**
 * Created by PhpStorm.
 * User: lxy
 * Date: 2016/1/15
 * Time: 19:47
 */

namespace app\lib\wxpay;


class PayNotifyCallBack extends WxPayNotify
{
    //查询订单
    public function Queryorder($transaction_id)
    {
        return true;
    }

    //重写回调处理函数
    public function NotifyProcess($data, &$msg)
    {


        if (!array_key_exists("transaction_id", $data)) {
            $msg = "输入参数不正确";
            return false;
        }
        //查询订单，判断订单真实性
        if (!$this->Queryorder($data["transaction_id"])) {
            $msg = "订单查询失败";
            return false;
        }
        //写入数据库
//        file_put_contents('d://return_code.txt',$data['return_code'] );
        if($data['return_code']=='SUCCESS'){
            $err_code_des='';
            if(array_key_exists('err_code_des',$data))
                $err_code_des=$data['err_code_des'];
//            file_put_contents('d://json.txt',json_encode([$data['result_code'],$err_code_des
//                ,$data['openid'],$data['total_fee'],$data['out_trade_no'],$data['time_end'],$data['attach']]) );
            $re= T_WX_PAY_LOG::write_P_WXMALL_PAY_ORDER($data['result_code'],$err_code_des
                ,$data['openid'],$data['total_fee'],$data['out_trade_no'],$data['time_end']
                ,$data['attach']);
//            file_put_contents('d://re.txt',$re );
        }

        return true;
    }
    /*{
    "appid" : "wx6c0b8bc08df431a6",
    "bank_type" : "CFT",
    "cash_fee" : "1",
    "fee_type" : "CNY",
    "is_subscribe" : "Y",
    "mch_id" : "1300940201",
    "nonce_str" : "ljbkhzb5unyyjlkfcbiwi9q977n1981n",
    "openid" : "ozSzqwoHxdTrhrSQ5HvAzSZ2Fnqc",
    "out_trade_no" : "WD_0000_2016_1174",
    "result_code" : "SUCCESS",
    "return_code" : "SUCCESS",
    "sign" : "6830D1096D6544CCE774F557E67FD14B",
    "time_end" : "20160115091430",
    "total_fee" : "1",
    "trade_type" : "JSAPI",
    "transaction_id" : "1002880719201601152705512038"
    }*/
}